<?php

namespace Home\Controller;
use Think\Controller;

class WebserController extends Controller {
	public function webser() {
		$show = D("getareadataset");
		$list = $show->select();
		foreach($list as $key=>$val){
                    // var_dump($val);
        }
        // var_dump($list);
        $this->assign("list", $list);
        $this->display();
	}
	public function wsdl() {
		header ( "Content-Type: text/html; charset=utf-8" );
		//使用soap调用Web Service接口
		$soap = new \SoapClient('http://ws.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx?wsdl');
		//获取getAreaDataSet的数据，并转换为数组
		$getsoap = json_decode(json_encode($soap->getAreaDataSet()),TRUE);
		// var_dump($getsoap["getAreaDataSetResult"]["any"]);
		//将获取的xml数据进行处理
		$p = xml_parser_create();
		xml_parse_into_struct($p, $getsoap["getAreaDataSetResult"]["any"], $vals, $index);
		xml_parser_free($p);
		// var_dump($vals);

		$arr1 = array();
		$arr2 = array();
		$tv = D("getareadataset");
		//获取数据
		foreach ($vals as $key => $value) {
				if($value["tag"] == "AREAID"){
					$arr1['areaID'] = $value["value"];
				}
				if($value["tag"] == "AREA"){
					$arr1['area'] = $value["value"];
				}
				if($value["tag"] == "ZONE"){
					$arr1['zone'] = $value["value"];
					array_push($arr2, $arr1);//将数值以3个为一组压到同一个数组
					$tv->add($arr1);//将数组添加到数据库
				}
				
			
		}
		var_dump($arr2);

		$this->response("获取成功",'json');
		

		// array_push(array, var)
		// var_dump($index);
		// var_dump ( $soap->__getFunctions () );//获取服务器上提供的方法
		// echo ('</pre>');
		// echo ("SOAP服务器提供的Type:");
		// echo ('<pre>');
		// var_dump ( $soap->__getTypes () );//获取服务器上数据类型
		
	}

}